<?php
namespace Home\Controller;
use Home\Common\Common;

class ResumeController extends Common {
    public function index(){
        $admin = M('resumeinfo');  //直接实例化表为模型
        if (empty($_GET['search']) || empty($_GET['value'])){
            $where='states=1';
        }else{
            $where=array( '`preson` like "%'.$_GET['value'].'%" or `rmd_study` like "%'.$_GET['value'].'%"','states'=>1);
            $this->assign('value',$_GET['value']);
        }
        $count = $admin->where($where)->count();  //统计输出到页面的数据总条数
        $page = new \Think\Page($count,4); //实例化thinkphp的分页类
        $show = $page->show(); //输出分页
        //limit('0,5')   limit('6,10')
        $list = $admin->where($where)->limit($page->firstRow.','.$page->listRows)->order('rmn_id')->select();  //取出当前页的数据
        $this->assign('count',$count);  //将计数的数据输出到视图
        $this->assign('show',$show);  //将分页信息输出到视图
        $this->assign('list',$list);  //将数据输出到视图
        $this->display();
    }

    public function recovery(){
        $admin = M('resumeinfo');  //直接实例化表为模型
        if (empty($_GET['search']) || empty($_GET['value'])){
            $where='states=0';
        }else{
            $where=array( '`preson` like "%'.$_GET['value'].'%" or `rmd_study` like "%'.$_GET['value'].'%"','states'=>1);
            $this->assign('value',$_GET['value']);
        }
        $count = $admin->where($where)->count();  //统计输出到页面的数据总条数
        $page = new \Think\Page($count,8); //实例化thinkphp的分页类
        $show = $page->show(); //输出分页
        //limit('0,5')   limit('6,10')
        $list = $admin->where($where)->limit($page->firstRow.','.$page->listRows)->order('rmn_id')->select();  //取出当前页的数据
        $this->assign('count',$count);  //将计数的数据输出到视图
        $this->assign('show',$show);  //将分页信息输出到视图
        $this->assign('list',$list);  //将数据输出到视图
        $this->display();
    }

    public  function add(){
        if (empty($_POST['submit'])){
            $this->display();
        }else{
           if(empty($_POST['preson'])||is_null($_POST['sex'])||empty($_POST['age'])||empty($_POST['rmd_study'])||empty($_POST['rmd_seniority'])||empty($_POST['rmd_intention'])||empty($_POST['rmd_pubtime'])){
                $this->error('请完善数据！');
            }
            if(($_POST['age']<18)){
                $this->error('年龄不够');
            }
            $admin = D('resumeinfo');
            if (!$admin->create()){
                $this->error($admin->getError());
            }
            $role = M('resumeinfo');
            $role->add($_POST);
            $this->success('添加成功',U('index'));
        }
    }

    public function edit(){
        if (empty($_POST['submit'])){
            if (empty($_GET['rmn_id'])) {
                $this->error('参数错误', U('index'));
            }
            $admin = M('resumeinfo');
            $info = $admin->where('`rmn_id`='.$_GET['rmn_id'])->find();
            $this->assign('info',$info);
            $this->display();
        }else{
          if(($_POST['age']<18)){
                $this->error('年龄不够');
            }
            $admin = D('resumeinfo');
            $admin->where('`rmn_id`='.$_POST['rmn_id'])->save($_POST);
            $this->success('修改成功',U('index'));
        }
    }

    public function del(){
        if (empty($_GET['rmn_id'])){
            $this->error('参数错误',U('index'));
        }else{
            $admin = M('resumeinfo');
            $admin->where('rmn_id='.$_GET['rmn_id'])->save(array('states'=>0));
            $this->success('删除成功',U('index'));
        }
    }
    public  function  auth(){
        if (empty($_POST['submit'])){
            if (empty($_GET['rmn_id'])) {
                $this->error('参数错误', U('index'));
            }
            $admin = M('resumeinfo');
            $admin2 =M('staffinfo');
            $list=$admin->where('`rmn_id`='.$_GET['rmn_id'])->select();
            if($list[0]['state']==1){
                $this->error('已经审批过了',U('index'));
            }
            $info = $admin->where('`rmn_id`='.$_GET['rmn_id'])->find();
            $info2=$admin2->where('`stf_id`='.$_SESSION['aid'])->find();
            $this->assign('info2',$info2);
            $this->assign('info',$info);
            $this->display();
        }else{
            $admin = D('resumeinfo');
            $admin->where('`rmn_id`='.$_POST['rmn_id'])->save($_POST);
            $this->success('审批完成',U('index'));
        }
    }
    public function del_all(){
        if(empty($_POST['rmnid'])){
            $this->error('参数错误');
        }
        $resumeinfo=M('resumeinfo');
        foreach ($_POST['rmnid'] as $value){
            $resumeinfo->where('rmn_id='.$value)->save(array('states'=>0));
        }
        $this->success('影藏成功！',U('index'));
    }

    public function rdel_all(){
        if(empty($_POST['rmnid'])){
            $this->error('参数错误!');
        }
        $recruitinfo=M('resumeinfo');
        foreach ($_POST['rmnid'] as $value){
            $recruitinfo->where('rmn_id='.$value)->save(array('states'=>1));
        }
        $this->success('恢复成功！',U('recovery'));
    }

    public function r_del(){
        if (empty($_GET['rmn_id'])){
            $this->error('参数错误',U('index'));
        }else{
            $admin = M('resumeinfo');
            $admin->where(array('rmn_id'=>$_GET['rmn_id']))->delete();
            $this->success('删除成功',U('index'));
        }
    }
  public function r_edit(){
        if (empty($_GET['rmn_id'])){
            $this->error('参数错误',U('index'));
        }else{
            $admin = M('resumeinfo');
           $admin->where('rmn_id='.$_GET['rmn_id'])->save(array('states'=>1));
            $this->success('恢复成功',U('index'));
        }
    }
}